<?php
namespace app\controllers;


use app\common\ApiResponse;
use yii\filters\auth\CompositeAuth;
use yii\filters\auth\HttpBearerAuth;

class HttpBearerAuthController extends \yii\rest\Controller
{
    /**
     * @var ApiResponse
     */
    protected ApiResponse $_api;

    public function behaviors(): array
    {
        $behaviors = parent::behaviors();
        $behaviors['authenticator'] = [
            'class' => CompositeAuth::class,
            'authMethods' => [
                //配置API接口认证方式
                HttpBearerAuth::class,
            ],
        ];
        // HTTP 头发送目前的速率限制信息
        $behaviors['rateLimiter']['enableRateLimitHeaders'] = false;
        return $behaviors;
    }

    /**
     * @param $id
     * @param $module
     * @param $config
     */
    public function __construct($id, $module, $config = [])
    {
        parent::__construct($id, $module, $config);
        $this->_api = new ApiResponse();
    }

    public function actionIndex(): array
    {
        return $this->_api->success([
            'authMethods'=>'HttpBearerAuth'
        ]);
    }

}